using System;
using System.Collections.Generic;
using System.Text;

namespace Rest
{
    /// <summary>
    /// Represents a parameter passed as part of a REST request.
    /// </summary>
    public class RestParameter : IRestParameter
    {
        #region Properties
        private String name;
        private String value;

        /// <summary>
        /// The parameter name
        /// </summary>
        public String Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// The value for the parameter
        /// </summary>
        public String Value
        {
            get { return this.value; }
            set { this.value = value; }
        }
        #endregion

        /// <summary>
        /// ctor
        /// </summary>
        public RestParameter()
        { }

        /// <summary>
        /// ctor : String, String
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public RestParameter(String name, String value) 
        {
            this.name = name;
            this.value = value;   
        }

        /// <summary>
        /// Gets the raw bytes representing the current instance. 
        /// Designed for use with HTTP methods requiring binary transfer like POST.
        /// </summary>
        /// <param name="encoding">The encoding to use</param>
        /// <returns></returns>
        protected virtual Byte[] GetByteValue(System.Text.Encoding encoding)
        {
            return encoding.GetBytes(Value);
        }

        /// <summary>
        /// Gets the bytes representing the current instance, using UTF8 encoding. 
        /// Designed for use with HTTP methods requiring binary transfer like POST.
        /// </summary>
        /// <returns></returns>
        public Byte[] GetBytes()
        {
            return GetByteValue(Encoding.UTF8);  
        }
    }
}
